home *** CD-ROM | disk | FTP | other *** search
- Path: alterdial.uu.net!not-for-mail
- From: rogerst@approach.com (Tom Rogers)
- Newsgroups: comp.lang.c
- Subject: Re: Tradition or what?
- Date: Fri, 08 Mar 1996 16:36:56 GMT
- Message-ID: <4hpd8a$d70@alterdial.UU.NET>
- References: <4g0elg$mdr@redstone.interpath.net> <4h0bbo$c0q@fohnix.metronet.com> <4h7ce0$ojd@news.interpath.net> <4h85sm$lm0@texas.nwlink.com> <danpop.825961872@rscernix> <313C5CD1.1209@oc.com> <4hmos4$ij2@news.interpath.net>
- NNTP-Posting-Host: 198.177.211.32
- X-Newsreader: Forte Free Agent 1.0.82
-
- softbase@mercury.interpath.net (Scott McMahan - Softbase Systems)
- wrote:
-
- >Larry Weiss (lfw@oc.com) wrote:
- >
- >: > Actually, the second rule is quite good (except that '2' should be replaced
- >: > by '1' :-) Magic constants embedded in the code are a huge nuisance
- >: > for maintenability. [...]
-
- >: I agree that there are good uses for giving a literal a name, and using
- >: that name instead of repeated usage of the literal, but to make a
- >: mandate that even if the literal were referenced only once you must give
- >: it a name would seem too extreme.
-
- >From personal experience, I think you can't be too extreme. I've been
- >burned by literals before. I've come to the conclusion that magic
- >numbers in the code are evil and should be done away with. Anything
- >that isn't a universal, unchanging constant (like an integer being 32
- >bits :)), something like a law of physics, needs to be a constant in
- >the program. I always #define it, too, since C has broken const
- >constants that can't be used as initializers (which defeats the whole
- >point of const).
-
- >Scott
-
- I agree, Scott. Magic numbers are evil. Don't use them not even
- once. Your code will be reused, by you or someone else. Even if
- you just use a magic number in one place it doesn't mean that in
- the future your routines won't get included in some other module
- with other new routines that need to use the 'same' magic number.
-
- Furthermore, what does 5 or 7 or 10 mean? It is NOT self documenting.
- Make it a well named constant and reduce the need for accompanying
- comments describing what the value is.
-
- Tom
-
-
-